<template>
	<view class="content">
		<view class="goods_bottom" @scrolltolower="scrolltolower"
			 v-for="(item,index) in title" :key="item.goods_id">
			<view class="radio">
				<block class="radio">
					<radio style="transform:scale(0.7)" color="#EB4450" :checked="item.isSelect" @tap="tipch(index)"/>
				</block>
			</view>
			<view class="bottom_commodity">
				<image :src=" item.goods_big_logo || '../../static/tads/empty.png' " mode=""></image>
				<view class="bottom_commodity_rigth">
					<navigator class="bottom_commodity_rigth_top" :url="'../goods_detail/index?goods_id='+item.goods_id " open-type="navigate">
						{{item.goods_name}}
					</navigator>
					<view class="bottom">
						<view class="price">
							{{item.goods_price}}
						</view> 
						<view class="unmber">
							<view class="iconfont icon-jianshao" @tap="add_and(index,-1)"></view>
							<view class="unmber_">{{item.quantity}}</view>
							<view class="iconfont icon-zengjia" @tap="add_and(index,1)"></view>
						</view>
					</view>
				</view>
			</view>
			
		</view>
		<view class="sloce">
			<view class="total">
				<label class="radio">
					<radio value="" style="transform:scale(0.7)" color="#DD524D" :checked="check" /><view>全选</view>
				</label>
				<view class="huji">
					合计：
				</view>
				<view class="price">
					{{ total_price }}
				</view>
			</view>
			<view class="go_sloce">
				<view class="payment" @tap="go_price">
					去结算({{ product }})
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: [],
				check: false,
			}
		},
		onLoad() {

		},
		computed:{
			total_price() {
				let price = 0
				this.title.forEach(item=>{
					if(item.isSelect){
						price += item.goods_price * item.quantity
					}
				})
				return price
			},
			product() {
				let arr = 0
				this.title.forEach(v=>{
					if(v.isSelect == true) {
						arr++
					}
				})
				return arr
			}
		},
		watch: {
			title: {
				handler() {
					uni.setStorageSync('cartData',this.title)
					this.tipch()
				},
				deep: true
			}
		},
		methods: {
			add_and(index,number) {
				if(number == -1 && this.title[index].quantity == 1){
					uni.showModal({
						content:"是否删除",
						confirmText	:"删除",
						confirmColor: '#afafaf',
						icon:"none",
					}).then(res=>{
						if(res[1].confirm){
							this.title.splice(index,1)
						}else {
							return
						}
					})
				}else {
					this.title[index].quantity += number
				}
			},
			tipch(index) {
				if(index != undefined){
					this.title[index].isSelect = !this.title[index].isSelect
				}
				if(this.title.length == 0) {
					return this.check = false
				}
				this.check = this.title.every(item=>item.isSelect)
			},
			go_price() {
				const condition = this.title.filter(v=>v.isSelect)
				if( condition != 0 ) {
					uni.navigateTo({
						url: '/pages/pay/index',
					})
				}else {
					uni.showToast({
						icon: "none",
						title: "未选择商品"
					})
				}
			}
		},
		onShow() {
			const list = uni.getStorageSync('cartData')
			this.title = list  
		}
	}
</script>

<style lang="less">
.goods_bottom {
	display: flex;
	position: relative;
	.radio {
		flex: 2;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.bottom_commodity {
		flex: 9;
		padding: 20rpx;
		display: flex;
		image {
			width: 190rpx;
			height: 190rpx;
			flex-shrink: 0;
		}
		.bottom_commodity_rigth {
			flex: 1;
			font-size: 24rpx;
			padding: 20rpx 20rpx 0;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.bottom_commodity_rigth_top {
				font-size: 24rpx;
				overflow : hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 3;
				-webkit-box-orient: vertical;
			}
			.bottom {
				display: flex;
				justify-content: space-between;
				align-items: center;
				.price {
					color: red;
					&::before {
						content: "￥";
						padding-right: 10rpx;
					}
				}
				.unmber {
					display: flex;
					justify-content: space-between;
					align-items: center;
					min-width: 160rpx;
					font-size: 30rpx;
					margin-right: 20rpx;
				}
			}
		}
	}
}
.sloce {
	position: fixed;
	bottom: 0;
	width: 750rpx;
	height: 84rpx;
	display: flex;
	font-size: 30rpx;
	padding: 0 30rpx;
	box-sizing: border-box;
	background-color: #FFFFFF;
	.total {
		flex: 1;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		.radio {
			display: flex;
			justify-content: center;
			align-items: center;
		}
		.huji {
			padding-left: 20rpx;
		}
		.price {
			color: red;
			&::before {
				content: "￥";
				font-size: 24rpx;
			}
		}
	}
	.go_sloce {
		flex: 1;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		.payment {
			width: 150rpx;
			height: 52rpx;
			background: #ea4350;
			color: #FFFFFF;
			border-radius: 75rpx;
			text-align: center;
			line-height: 52rpx;
		}
	}
}
</style>
